
<%@page import="java.util.LinkedList"%>
<%@page import="java.util.List"%>
<%@page import="ejb.Utente"%>
<%@page import="ejb.ArticoloNuovo"%>
<%@page import="ejb.ArticoloUsato"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@include file="wrapper.jsp" %>
<%
    Utente utSession = (Utente) session.getAttribute("utente");
    String tipo= utSession.getTipo();
%>
    
<div class="container"> 
      <div class="row-fluid">
        <div class="span3 bs-docs-sidebar">
        <ul class="nav nav-list bs-docs-sidenav">
            <%if(tipo.equals("a")){
            %>
                <li><a href="Controller?button=visualizzaArticoli&typeView=All"> 
                <button class="btn btn-large btn-inverse btn-block"><i class="icon-white icon-th-list"></i> Tutti gli Articoli</button> </a></li>
                <li><a href="Controller?button=modificaCancellaArtNuovi"> 
                <button class="btn btn-large btn-inverse btn-block"><i class="icon-white icon-th-list"></i> Articoli Nuovi</button> </a></li>
                <li><a href="Controller?button=modificaCancellaArtUsati&confirm=n"> 
                <button class="btn btn-large btn-inverse btn-block"><i class="icon-white icon-th-list"></i> Articoli Usati</button> </a></li>
                <li><a href="Controller?button=articoloNuovo"> 
                <button class="btn btn-large btn-inverse btn-block"><i class="icon-white icon-plus"></i> Aggiungi Art. Nuovo</button> </a></li>
            <%}
            else if(tipo.equals("u")){
            %>
            <li><a href="Controller?button=visualizzaArticoli&typeView=All"> 
            <button class="btn btn-large btn-inverse btn-block"><i class="icon-white icon-th-list"></i> Tutti gli Articoli</button> </a></li>
            <li><a href="Controller?button=visualizzaArticoli&typeView=Mine"> 
            <button class="btn btn-large btn-inverse btn-block"><i class="icon-white icon-user"></i> I miei Articoli</button> </a></li>
            <li><a href="Controller?button=vendiArticolo"> 
            <button class="btn btn-large btn-inverse btn-block"><i class="icon-white icon-retweet"></i> Vendi Articolo</button> </a></li>
            <%}%>
        </ul>
      </div>
          
          
 <div class="span6">
     
     <ul style="margin: 0;padding: 0;list-style-type:none">

              <%
              LinkedList<ArticoloNuovo> carrello = (LinkedList<ArticoloNuovo>)session.getAttribute("carrello");
              Integer totCarrello=0;
              List<ArticoloUsato> usatiDaConfermare= (List<ArticoloUsato>)session.getAttribute("usatiDaConfermare");
              try{
                  String tipiArticoli = (String)request.getAttribute("tipiArticoli");
                  List<ArticoloUsato> usati=null;
                  List<ArticoloNuovo> nuovi=null;
                  
                  if(tipiArticoli.equals("both")){
                    nuovi = (List<ArticoloNuovo>)request.getAttribute("artNuovi");
                    usati = (List<ArticoloUsato>)request.getAttribute("artUsati");
                    if(!nuovi.isEmpty()){%>
                    
                    <%
                        for(ArticoloNuovo an : nuovi){ %>
                        
                        <li class="thumbnail">
                                <a href="Controller?button=visualizzaArticoli&amp;typeView=One&typeArt=nuovo&artCode=<%=an.getId()%>">
                                <img height="100" width="80" src="<%=an.getPathImmagine()%>" alt="" style="padding-left:10px;padding-top:5px"><span style="padding-left:10px"><%=an.getNome() %></span>
                                </a>
                                <p align="right">
                                <%if(tipo.equals("a")){%>
                                    <a href="Controller?button=modificaArtNuovo&id=<%=an.getId()%>">
                                    <button class="btn btn-inverse btn-small"><i class="icon-white icon-wrench"></i> Modifica</button>
                                    </a>
                                    <a href="Controller?button=cancellaArtNuovo&id=<%=an.getId()%>">
                                    <button class="btn btn-inverse btn-small"><i class="icon-white icon-trash"></i> Cancella</button>
                                    </a>
                                <%}%>
                                <b>Nuovo</b>
                                </p>
                        </li>
                   <%}
                   }
                    
                     if(!usati.isEmpty()){ %>
                     
                     <% 
                      for(ArticoloUsato au : usati){  %>
                      
                      <li class="thumbnail">
                             <a href="Controller?button=visualizzaArticoli&amp;typeView=One&typeArt=usato&artCode=<%=au.getId()%>" >
                             <img height="100" width="80" src="<%= au.getPathImmagine()%>" alt="" style="padding-left:10px;padding-top:5px"><span style="padding-left:10px"><%=au.getNome()%></span>
                             </a>
                             <p align="right">
                             <%if(tipo.equals("a") || au.getUtente().getUsername().equals(utSession.getUsername())){%>
                             <a href="Controller?button=modificaArtUsato&id=<%=au.getId()%>">
                             <button class="btn btn-inverse btn-small"><i class="icon-white icon-wrench"></i> Modifica</button>
                             </a>
                             <a href="Controller?button=cancellaArtUsato&id=<%=au.getId()%>&idUser=<%=utSession.getId()%>">
                             <button class="btn btn-inverse btn-small"><i class="icon-white icon-trash"></i> Cancella</button>
                             </a>
                             <%}%>
                            <b>Usato</b></p>
                      </li>
                      
                      <%}
                      }
                  }
                  
                  if(tipiArticoli.equals("nuovi")){
                    nuovi = (List<ArticoloNuovo>)request.getAttribute("artNuovi");
                    
                    if(!nuovi.isEmpty()){ 
                        for(ArticoloNuovo an : nuovi){ %>
                        
                            <li class="thumbnail"> 
                                <a href="Controller?button=visualizzaArticoli&amp;typeView=One&typeArt=nuovo&artCode=<%=an.getId()%>" >
                                <img height="100" width="80" src="<%=an.getPathImmagine()%>" style="padding-left:10px;padding-top:5px"><span style="padding-left:10px"><%=an.getNome() %></span>
                                </a>
                                <p align="right"><b>Nuovo</b></p>
                            </li>
                          <%}%>
                        
                   <% }
                  }
                  
                  if(tipiArticoli.equals("usati")){
                      usati = (List<ArticoloUsato>)request.getAttribute("artUsati");
                      if(!usati.isEmpty()){%>
                      
                      <%
                        for(ArticoloUsato au : usati){ %>
                           
                           <li class="thumbnail">
                                <a href="Controller?button=visualizzaArticoli&amp;typeView=One&typeArt=usato&artCode=<%=au.getId()%>" >
                                <img height="100" width="80" src="<%=au.getPathImmagine()%>" style="padding-left:10px;padding-top:5px"><span style="padding-left:10px"><%=au.getNome() %></span></a>
                                <%if(au.getUtente().getUsername().equals(utSession.getUsername())){%>
                                <p align="right">
                                <a href="Controller?button=modificaArtUsato&id=<%=au.getId()%>">
                                <button class="btn btn-inverse btn-small"><i class="icon-white icon-wrench"></i> Modifica</button>
                                </a>
                                <a href="Controller?button=cancellaArtUsato&id=<%=au.getId()%>&idUser=<%=utSession.getId()%>">
                                <button class="btn btn-inverse btn-small"><i class="icon-white icon-trash"></i> Cancella</button>
                                </a>
                                <b>Usato</b></p>
                            </li>
                        <%}
                        }%>
                      
                      <%
                       }
                  }
                   if(tipiArticoli.equals("nessuno")){
                      %>
                       
                       <li><h2><span>Nessun risultato trovato.</span></h2></li>
                       
                       <% 
                   }%>
                   
              </ul>
                
                   <%
                  }catch(Exception e){e.printStackTrace();}
                  %>

     </div>          
    
                  
    <div class="span3">
            <%
            if(tipo.equals("u")){
            %>
            <div class="thumbnail">
                  <p><b>Carrello</b></p>
                  <table>
                  <tr><td></td><td style="padding-left: 5px"><b>Articolo</b></td><td style="padding-left: 5px"><b>Costo</b></td></tr>
                  <tr><td><br></td><td><br></td><td><br></td></tr>
                  <% 
                  for(ArticoloNuovo a:carrello){
                      totCarrello= totCarrello + a.getPrezzo();
                  %>
                  <tr>
                  <p>
                   <td>
                        <a href="Controller?button=removeCarrello&amp;idArticolo=<%=a.getId()%>">
                            <button class="btn btn-inverse btn-mini"><i class="icon-white icon-trash"></i></button>
                        </a>
                    </td>
                  <td style="padding-left: 5px;height: 20px;width:100%;overflow:hidden;float:left"><%=a.getNome()%></td>
                  <td style="padding-left: 5px"><%=a.getPrezzo().toString()%> €</td>
                  </p>
                  </tr>
                  <tr><td><br></td><td><br></td><td><br></td></tr>
                  <%}%>
                  <tr><td></td><td><b>Totale</b></td><td style="padding-left: 5px"><%=totCarrello.toString()%> €</td></tr>
                  </table>
              </div>
              <br>
              <br>
              <form  class="navbar-search" action="Controller" value="cercaArticolo">
                    <input type="text" name="keywordRicerca" class="search-query span3" style="width:220px;" placeholder="Cerca">
                    <div class="icon-search" ></div>
                    <input type="hidden" name="button" value="cercaArticolo"/>
                    <br>
                    <br>
                    <input type="radio" name="tipiArticoli" value="n" style="padding-left: 10px"/><span> Nuovi</span> <br>
                    <input type="radio" name="tipiArticoli" value="u" style="padding-left: 10px"/><span> Usati</span> <br>
                    <input type="radio" name="tipiArticoli" value="both" checked="true" style="padding-left: 10px"/><span> Entrambi</span> 
                </form>
            <%}
            else if(tipo.equals("a")){%>
            <div class="thumbnail">
                 <p><b>Notes</b></p>
                 <br>
                 <% if(!usatiDaConfermare.isEmpty()){%>
                    <p> Ancora <%=usatiDaConfermare.size()%> articoli da confermare </p>
                    <br>
                    <p align="center">
                        <a href="Controller?button=modificaCancellaArtUsati&amp;confirm=s">
                            <button class="btn btn-inverse btn-small"><i class="icon-white icon-th-list"></i> Vedi Articoli da confermare</button>
                        </a>
                    </p>
                 <%}else{%>
                 <p> Nessun articolo da confermare </p>
                <%}%>      
            </div>
           <%}%>
         </div>          


</div>
</body>
</html>

 

 